
import com.sun.source.tree.BinaryTree;

import java.util.Locale;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User:
 * Date: 2024-07-22
 * Time: 10:01
 */
/*class Solution {
    public String truncateSentence(String s, int k) {
        int n = s.length();
        int end = 0, count = 0;
        for (int i = 1; i <= n; i++) {
            if (i == n || s.charAt(i) == ' ') {
                count++;
                if (count == k) {
                    end = i;
                    break;
                }
            }
        }
        return s.substring(0, end);
    }
}
public class Test {
    public static void main(String[] args) {
        Solution solution = new Solution();
        String str = solution.truncateSentence("hello how are you Contest",4);
        System.out.println(str);
    }


}*/








/*
class Solution{
    public String isSbustring(String s,int k){
        int count = 0;
        int end = 0;
        int n  = s.length();
        for (int i = 1; i <= n ; i++) {
            if(i == n  || (s.charAt(i) == ' ')){
                count++;
                if(count == k){
                    end = i;
                    break;
                }
            }
        }
        return s.substring(0,end);
    }
}

public class Test{
    public static void main(String[] args) {
        Solution solution = new Solution();
        String str = solution.isSbustring("hello how are you Contest", 4);
        System.out.println(str);
    }
}
*/












class Solution{
    public boolean isNumberAndCharacter(char ch){
        if(Character.isDigit(ch) || Character.isLetter(ch)) {
            return true;
        }
        return false;
    }

    public boolean isPalindrome(String s){
        s =s.toLowerCase();  //字符串中的字母转为小写
        int left = 0;
        int right = s.length() - 1;
        while(left < right){
            while(left < right && isNumberAndCharacter(s.charAt(left))){
                left++;
            }
            while(left < right && isNumberAndCharacter(s.charAt(right))){
                right--;
            }
            if(s.charAt(left) == s.charAt(right)){
                left++;
                right--;
            }else{
                return true;
            }
        }
        return false;
    }

}
/*
public class Test{
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.println(solution.isPalindrome("abcdefg"));
    }
}

*/







class Soltion{
    public boolean isNumberAndCharacter(char ch){
        if(Character.isDigit(ch) || Character.isLetter(ch)){
            return true;
        }
        return false;
    }


    public boolean isPanomy(String s ){
        s.toLowerCase(Locale.ROOT);
        int left = 0;
        int right = s.length() - 1;
        while(left < right){
            if(left < right && isNumberAndCharacter(s.charAt(left))){
                left++;
            }
            if(left < right && isNumberAndCharacter(s.charAt(right))){
                right--;
            }
           if(s.charAt(left) == s.charAt(right)){
               left++;
               right--;
           }else{
               return true;
           }
        }
        return false;
    }
}


public class Test {
    public static void main(String[] args) {
        Solution solution = new Solution();
        System.out.print(solution.isPalindrome("abcdfe"));
    }
}




























